import { fileURLToPath, URL } from 'node:url'
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import path from "path";
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from "unplugin-auto-import/vite";
//vite自带调试工具
// import vueDevTools from 'vite-plugin-vue-devtools'

import vueSetupExtend from "unplugin-vue-setup-extend-plus/vite";


// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
     vueSetupExtend({
      // 可选配置项
      // enableAutoExpose: true,
    }),
    AutoImport({
      imports: ["vue", "vue-router"],
    }),
    createSvgIconsPlugin({
      // Specify the icon folder to be cached
      iconDirs: [path.resolve(process.cwd(), "src/assets/icons/svg")],
      // Specify symbolId format
      symbolId: "icon-[dir]-[name]",
    }),

    // vueDevTools(),
  ],
  //@
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
    extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],//配置文件后缀名
  },
  //代理跨域
  server: {
    port: 80,
    host: true,
    open: true,
    proxy: {
      // https://cn.vitejs.dev/config/#server-proxy
      "/dev-api": {
        target: "http://192.168.1.40:8080",
        // target: "http://192.168.1.40:8080",
        // target: "https://app.hnlyzy.cn:6443/prod-api/",
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/dev-api/, ""),
      },
      "/dev-api2": {
        target: "http://sph-api.atguigu.cn",
        // target: 'https://heimahr.itheima.net',
        changeOrigin: true,

        rewrite: (p) => p.replace(/^\/dev-api2/, ""),
      },
    },
  },
});
